/**
 * Unicorn Admin Template
 * Diablo9983 -> diablo9983@gmail.com
**/
$(document).ready(function(){
	/*if($(this).find('colorpicker').exist()) {
		
	}
	$('body').find('.Mandatory').length;*/
	if($('.colorpicker').length){
		$('.colorpicker').colorpicker();
	}
	if($('.usertokenfield').length){
		$('.usertokenfield').tokenfield();
	}
	if($('.switch').length){
		$('.switch').bootstrapSwitch();
	}
	if($('.check').length){
		$('.check').iCheck({
			checkboxClass: 'icheckbox_square-blue',
			radioClass: 'iradio_square-blue',
			increaseArea: '20%' // optional
		});
	}
	if($('.datepicker').length){
		$('body').on('focus',".datepicker", function(){
			$(this).datepicker();
		});
		//$('.datepicker').datepicker();
	}
	if($('.selectpicker').length){
		$('.selectpicker').selectpicker();
	}
	if($('.tooltips').length){
		$('.tooltips').tooltip();
	}
	
	

	//add method for select
	$.validator.addMethod("valueNotEquals", function(value, element, arg){
	  return arg != value;
	}, "Please Select an Item");
	//add method for nospace
	$.validator.addMethod("noSpace", function(value, element) { 
    return value.indexOf(" ") < 0 && value != ""; 
	}, "Space are not allowed");
	//add method for checkbox
	$.validator.addMethod('onecheck', function(value, ele) {
        return $("input:checked").length >= 1;
	}, 'Please Select Atleast One CheckBox')
	$.validator.addMethod('mincheck',function (value, element) {
		var aChecked = $('input[name='+$(element).attr('name')+']:checked');
		return ( aChecked.length > 1 ) ? true : false;
	},'please check atleast one checkbox');
	 //password validation
	$.validator.addMethod("regx", function(value, element, regexpr) {          
		return regexpr.test(value);
	}, "Please enter a valid format."); 
	$.validator.addMethod("firstletter", function(value, element) {          
		return !(/^[0-9]{1,}/.test(value));
		//return value.charAt(0) == true; 
	}, 'The first character cannot be a number');
	$.validator.addMethod("alphanumeric", function(value, element) {          
		return (/^[a-zA-Z0-9]+$/.test(value));
		//return value.charAt(0) == true; 
	}, 'Only letters and numbers are allowed');
	$.validator.addMethod("alphanumericcomplex", function(value, element) {          
		return (/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/.test(value));
		
		//return value.charAt(0) == true; 
	}, 'It must contain at least one lower case, one upper case characters and one number');
	 // Form Validation
    $("#registerform").validate({
		rules:{
			RegistrantOrganizationName:{
				required:true
			},
			RegistrantFirstName:{
				required: true,
			},
			RegistrantLastName:{
				required: true,
			},
			RegistrantAddress1:{
				required: true,
			},
			RegistrantCity:{
				required: true,
			},
			RegistrantProvince:{
				required: true,
			},
			RegistrantPostalCode:{
				required: true,
				number:true
			},
			RegistrantCountry:{
				required: true,
			},
			RegistrantEmailAddress:{
				required: true,
				email:true
			},
			RegistrantPhone:{
				required: true,
				number:true
			},
			
			newuid:{
				required: true,
			},
			
			newpw:{
				required: true,
				minlength:6,
				maxlength:20
			},
			confirmpw: {
                required:true,
				equalTo:"#newpw"
			},
			AuthQuestionType:{
				required:true,
			},
			AuthQuestionAnswer:{
				required:true,
			},
			
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.form-group').addClass('errorform');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.form-group').removeClass('errorform');
			$(element).parents('.form-group').addClass('success');
		}
	});
	 $("#forgot-form").validate({
		rules:{
			pemail:{
				required: true,
				email:true,
			},	
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
	$("#change_password").validate({
		rules:{
			password:{
				required:true
			},
			cpassword: {
                required:true,
				equalTo:"#npassword"
			},
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	$("#bulkdomainpurchase").validate({
		ignore: [],
		rules:{
			HostID:{
				required: true,
				firstletter:true,
				rangelength: [6, 10],
				alphanumeric:true,
			},
			
			HostPW:{
				required:true,
				alphanumeric:true,
				alphanumericcomplex:true,
				rangelength: [6, 14],
			},
			ReHostPW:{
				required:true,
				equalTo:"#HostPW"
			},
			
		},
		errorClass: "error",
		errorElement: "label",
		
		
		errorPlacement: function (error, element) {
			//alert(element.attr("name"));
			error.appendTo(element.parents('.form-group'))
			.wrap('<div class="col-sm-3"></div>');
       
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
	
});
